package com.mzpai.web.controller;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.gexin.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.mzpai.product.exception.ProductResExceptionCode;
import com.mzpai.product.model.SystemStore;
import com.mzpai.product.model.SystemStoreExtract;
import com.mzpai.product.service.StoreOrderService;
import com.mzpai.product.service.SystemStoreExtractService;
import com.mzpai.product.service.SystemStoreService;
import com.mzpai.product.util.ServiceChargeUtil;
import com.mzpai.product.vo.CountserviceChargeReqVo;
import com.mzpai.product.vo.QueryWithdrawalApplicateVo;
import com.mzpai.product.vo.SimpleSystemStoreExtractVo;
import com.mzpai.product.vo.StoreAccountVo;
import com.mzpai.product.vo.StoreExtractVo;
import com.mzpai.product.vo.WithdrawalApplicateReqVo;
import com.mzpai.product.vo.WithdrawalApplicateResultVo;
import com.mzpai.product.vo.WithdrawalApplicateScheduleVo;
import com.mzpai.product.vo.WithdrawalApplicateVo;
import com.mzpai.util.BeanUtils;
import com.mzpai.util.DateUtil;
import com.mzpai.util.StringUtils;
import com.mzpai.vo.ResponseVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
/**
 *
 * 商家提现表查询
 *
 */
@Api(value = "商家提现表接口")
@RestController
@RequestMapping("/systemStoreExtract")
public class SystemStoreExtractController extends BaseController {
	
	private static Logger log = LoggerFactory.getLogger(SystemStoreExtractController.class);

	@Autowired 
	private SystemStoreExtractService systemStoreExtractService;
	
	@Autowired 
	private SystemStoreService systemStoreService;
	
	@Autowired 
	private StoreOrderService storeOrderService;
	
	
	/**
	 * 
	 * @param queryProductByPageStr
	 * @return
	 */
	@ApiOperation(value = "提现申请")
    @RequestMapping(value = "/withdrawalApplicate",method = {RequestMethod. POST ,RequestMethod. GET })
    public ResponseVo<WithdrawalApplicateResultVo> withdrawalApplicate(
    		@ApiParam(required = true, name = "withdrawalApplicateStr", value = "入参为withdrawalApplicateStr")
    		@RequestParam(value = "withdrawalApplicateStr", required = true) String withdrawalApplicateStr){
		
		log.info("msg1=开始提现申请,,method=withdrawalApplicate,,reqVo={}",withdrawalApplicateStr);
		WithdrawalApplicateReqVo WithdrawalApplicateVo = JSONObject.parseObject(withdrawalApplicateStr, WithdrawalApplicateReqVo.class);
		
		Integer storeId=WithdrawalApplicateVo.getStoreId();
		String bankCode=WithdrawalApplicateVo.getBankCode();
		String bankName=WithdrawalApplicateVo.getBankName();
		String realName=WithdrawalApplicateVo.getRealName();
		String extractType=WithdrawalApplicateVo.getExtractType();
		BigDecimal amount=WithdrawalApplicateVo.getAmount();
		
		if(storeId==null){
			ResponseVo<WithdrawalApplicateResultVo> resVo=new ResponseVo<WithdrawalApplicateResultVo>();
			resVo.setCode(ProductResExceptionCode.STOREID_NULL.getCode());
			resVo.setMessage(ProductResExceptionCode.STOREID_NULL.getMessage());
			return resVo;
		}
		
		if(StringUtils.isNullOrBlank(bankCode)){
			ResponseVo<WithdrawalApplicateResultVo> resVo=new ResponseVo<WithdrawalApplicateResultVo>();
			resVo.setCode(ProductResExceptionCode.BANK_CODE_NULL.getCode());
			resVo.setMessage(ProductResExceptionCode.BANK_CODE_NULL.getMessage());
			return resVo;
		}
		
		if(StringUtils.isNullOrBlank(bankName)){
			ResponseVo<WithdrawalApplicateResultVo> resVo=new ResponseVo<WithdrawalApplicateResultVo>();
			resVo.setCode(ProductResExceptionCode.BANK_NAME_NULL.getCode());
			resVo.setMessage(ProductResExceptionCode.BANK_NAME_NULL.getMessage());
			return resVo;
		}
		
		if(StringUtils.isNullOrBlank(realName)){
			ResponseVo<WithdrawalApplicateResultVo> resVo=new ResponseVo<WithdrawalApplicateResultVo>();
			resVo.setCode(ProductResExceptionCode.REAL_NAME_NULL.getCode());
			resVo.setMessage(ProductResExceptionCode.REAL_NAME_NULL.getMessage());
			return resVo;
		}
		//bank = 银行卡 alipay = 支付宝weixin=微信
		if(StringUtils.isNullOrBlank(extractType)){
			ResponseVo<WithdrawalApplicateResultVo> resVo=new ResponseVo<WithdrawalApplicateResultVo>();
			resVo.setCode(ProductResExceptionCode.EXTRACT_TYPE_NULL.getCode());
			resVo.setMessage(ProductResExceptionCode.EXTRACT_TYPE_NULL.getMessage());
			return resVo;
		}
		
		if(amount==null){
			ResponseVo<WithdrawalApplicateResultVo> resVo=new ResponseVo<WithdrawalApplicateResultVo>();
			resVo.setCode(ProductResExceptionCode.AMOUNT_NULL.getCode());
			resVo.setMessage(ProductResExceptionCode.AMOUNT_NULL.getMessage());
			return resVo;
		}
		
		SystemStore systemStore=systemStoreService.queryByPrimaryId(storeId);
		Double nowMoney=systemStore.getNowMoney();
		
		if(nowMoney<amount.doubleValue()){
			ResponseVo<WithdrawalApplicateResultVo> resVo=new ResponseVo<WithdrawalApplicateResultVo>();
			resVo.setCode(ProductResExceptionCode.BALANCE_NOT_SUFFICIEN.getCode());
			resVo.setMessage(ProductResExceptionCode.BALANCE_NOT_SUFFICIEN.getMessage());
			return resVo;
		}
		
		//amount 提现金额>手续费校验
		//手续费
		Double serviceChargePrice=ServiceChargeUtil.countServiceCharge(amount.doubleValue());	
		if(amount.doubleValue()<serviceChargePrice){
			ResponseVo<WithdrawalApplicateResultVo> resVo=new ResponseVo<WithdrawalApplicateResultVo>();
			resVo.setCode(ProductResExceptionCode.AMOUNT_LESSTHAN_SERVICE_CHARGE.getCode());
			resVo.setMessage(ProductResExceptionCode.AMOUNT_LESSTHAN_SERVICE_CHARGE.getMessage());
			return resVo;
		}
		
		//提现校验如果有审核中的
		Map<String,Object> queryMap=new HashMap<String,Object>();
		queryMap.put("storeId", storeId);
		queryMap.put("status", 0);
		
		List<SystemStoreExtract> listSystemStoreExtract=systemStoreExtractService.getList(queryMap);
		if(listSystemStoreExtract!=null && !listSystemStoreExtract.isEmpty()){
			ResponseVo<WithdrawalApplicateResultVo> resVo=new ResponseVo<WithdrawalApplicateResultVo>();
			resVo.setCode(ProductResExceptionCode.ALREADY_EXISTALREADY_REVIEW.getCode());
			resVo.setMessage(ProductResExceptionCode.ALREADY_EXISTALREADY_REVIEW.getMessage());
			return resVo;
		}
		WithdrawalApplicateVo withdrawalApplicateVo=systemStoreExtractService.saveWithdrawalApplicate(WithdrawalApplicateVo);
		
		WithdrawalApplicateResultVo withdrawalApplicateResultVo=new WithdrawalApplicateResultVo();
		
		List<WithdrawalApplicateScheduleVo> listSchedule=new ArrayList<WithdrawalApplicateScheduleVo>();
		
		String dateTimeStr=DateUtil.getNow();
		WithdrawalApplicateScheduleVo scheduleVo1=new WithdrawalApplicateScheduleVo();
		scheduleVo1.setScheduleDate(dateTimeStr);
		scheduleVo1.setWithdrawalApplicateStatus("提现申请");
		
		WithdrawalApplicateScheduleVo scheduleVo2=new WithdrawalApplicateScheduleVo();
		scheduleVo2.setScheduleDate(dateTimeStr);
		scheduleVo2.setWithdrawalApplicateStatus("审核中");
		
		listSchedule.add(scheduleVo1);
		listSchedule.add(scheduleVo2);
		
		String accountWay=bankName+"("+bankCode.substring(bankCode.length()-4)+")";
		
		
		withdrawalApplicateResultVo.setAccountWay(accountWay);
		withdrawalApplicateResultVo.setStatus(0);
		withdrawalApplicateResultVo.setStatusDesc("审核中");
		withdrawalApplicateResultVo.setScheduleTime(dateTimeStr);
		withdrawalApplicateResultVo.setListSchedule(listSchedule);
		withdrawalApplicateResultVo.setServiceCharge(withdrawalApplicateVo.getServiceCharge());
		withdrawalApplicateResultVo.setAmount(withdrawalApplicateVo.getAccount());
		ResponseVo<WithdrawalApplicateResultVo> resVo=new ResponseVo<WithdrawalApplicateResultVo>();
		resVo.setResult(withdrawalApplicateResultVo);
		log.info("msg1=结束开始提现申请,,method=withdrawalApplicate");
    	return resVo;
    }
	
	
	@ApiOperation(value = "获取门店账户信息")
    @RequestMapping(value = "/queryStoreAccount",method = {RequestMethod. POST ,RequestMethod. GET })
    public ResponseVo<StoreAccountVo> queryStoreAccount(@RequestParam(value = "storeId", required = true) Integer storeId){
		
		log.info("msg1=开始获取门店账户信息,,method=queryStoreAccount,,storeId={}",storeId);
		if(storeId==null){
			ResponseVo<StoreAccountVo> resVo=new ResponseVo<StoreAccountVo>();
			resVo.setCode(ProductResExceptionCode.STOREID_NULL.getCode());
			resVo.setMessage(ProductResExceptionCode.STOREID_NULL.getMessage());
			return resVo;
		}
		SystemStore systemStore = systemStoreService.queryByPrimaryId(storeId);
		//总收入
		Double  totalMoney=systemStore.getTotalMoney();
		//可提现余额
		Double  nowMoney=systemStore.getNowMoney();
		
		StoreAccountVo storeAccountVo=new StoreAccountVo();
		
		Double totalPayPrict=storeOrderService.countTotalPayPrice(storeId, 2);
		if(totalPayPrict==null){
			storeAccountVo.setOfflineAccount("0");
		}else{
			storeAccountVo.setOfflineAccount(String.valueOf(totalPayPrict));
		}
		Double totalAccount=totalMoney+totalPayPrict;
		
		storeAccountVo.setCashBalance(String.valueOf(nowMoney));
		storeAccountVo.setOnlineAccount(String.valueOf(totalMoney));
		
		storeAccountVo.setTotalAccount(String.valueOf(totalAccount));
		
		
		SystemStoreExtract systemStoreExtract=systemStoreExtractService.queryLastStoreExtract(storeId);
		if(systemStoreExtract!=null){
			BigDecimal extractPrice=systemStoreExtract.getExtractPrice();
			Double extractPriceDouble=extractPrice.doubleValue();
			String realName= systemStoreExtract.getRealName();
			String bankCode=systemStoreExtract.getBankCode();
			String bankName=systemStoreExtract.getBankName();
			storeAccountVo.setBankCode(bankCode);
			storeAccountVo.setBankName(bankName);
			storeAccountVo.setRealName(realName);
			storeAccountVo.setExtractPrice(String.valueOf(extractPriceDouble));
		}
		
		ResponseVo<StoreAccountVo> resVo=new ResponseVo<StoreAccountVo>();
		resVo.setResult(storeAccountVo);
		log.info("msg1=结束获取门店账户信息,,method=queryStoreAccount,,storeId={}",storeId);
	    return resVo;
	}
	
	
	@ApiOperation(value = "获取门店下最后一条审核中或失败的数据")
    @RequestMapping(value = "/queryLastStoreExtract",method = {RequestMethod. POST})
    public ResponseVo<SimpleSystemStoreExtractVo> queryLastStoreExtract(@RequestParam(value = "storeId", required = true) Integer storeId){
		
		log.info("msg1=开始获取门店下最后一条审核中或失败的数据,,method=queryLastStoreExtract,,storeId={}",storeId);
		if(storeId==null){
			ResponseVo<SimpleSystemStoreExtractVo> resVo=new ResponseVo<SimpleSystemStoreExtractVo>();
			resVo.setCode(ProductResExceptionCode.STOREID_NULL.getCode());
			resVo.setMessage(ProductResExceptionCode.STOREID_NULL.getMessage());
			return resVo;
		}
		
		SystemStoreExtract systemStoreExtract=systemStoreExtractService.queryLastStoreExtract(storeId);
		
		SimpleSystemStoreExtractVo simpleSystemStoreExtractVo=null;
		if(systemStoreExtract!=null){
			Integer id=systemStoreExtract.getId();
			Integer status=systemStoreExtract.getStatus();
			BigDecimal extractPrice=systemStoreExtract.getExtractPrice();
			Double extractPriceDouble=extractPrice.doubleValue();
			
			Date passTime=systemStoreExtract.getPassTime();
			Date lastModifyDate=systemStoreExtract.getLastModifyDate();
			
			simpleSystemStoreExtractVo=new SimpleSystemStoreExtractVo();
			simpleSystemStoreExtractVo.setExtractPrice(String.valueOf(extractPriceDouble));
			simpleSystemStoreExtractVo.setId(id);
			simpleSystemStoreExtractVo.setStatus(status);
			simpleSystemStoreExtractVo.setStoreId(storeId);
			
			//-1 未通过 0 审核中 1 已提现
			if(status.equals(-1)){
				simpleSystemStoreExtractVo.setStatusDesc("未通过");
				simpleSystemStoreExtractVo.setStatus(-1);
			}else if(status.equals(0)){
				simpleSystemStoreExtractVo.setStatusDesc("审核中");
				simpleSystemStoreExtractVo.setStatus(0);
			}else if(status.equals(1)){
				simpleSystemStoreExtractVo.setStatusDesc("已提现");
				simpleSystemStoreExtractVo.setStatus(1);
			}
		}
		
		ResponseVo<SimpleSystemStoreExtractVo> resVo=new ResponseVo<SimpleSystemStoreExtractVo>();
		resVo.setResult(simpleSystemStoreExtractVo);
		
		log.info("msg1=结束获取门店下最后一条审核中或失败的数据,,method=queryLastStoreExtract,,storeId={}",storeId);
	    return resVo;
	}
	
	
		
	@ApiOperation(value = "提现明细清单列表")
	@RequestMapping(value = "/queryWithdrawalApplicateByPage",method = {RequestMethod. POST})
	public ResponseVo<PageInfo<StoreExtractVo>> queryWithdrawalApplicateByPage(
			@ApiParam(required = true, name = "queryWithdrawalApplicateByPageStr", value = "入参为queryWithdrawalApplicateByPageStr")
    		@RequestParam(value = "queryWithdrawalApplicateByPageStr", required = true) String queryWithdrawalApplicateByPageStr) throws Exception {
		
		log.info("msg1=开始提现明细清单列表,,method=queryWithdrawalApplicateByPage,,reqVo={}",queryWithdrawalApplicateByPageStr);
		QueryWithdrawalApplicateVo queryWithdrawalApplicateVo = JSONObject.parseObject(queryWithdrawalApplicateByPageStr, QueryWithdrawalApplicateVo.class);
		
		Integer pageIndex= queryWithdrawalApplicateVo.getPageIndex();
		Integer pageSize=queryWithdrawalApplicateVo.getPageSize();
		Integer storeId=queryWithdrawalApplicateVo.getStoreId();
		
		if(storeId==null){
			ResponseVo<PageInfo<StoreExtractVo>> resVo=new ResponseVo<PageInfo<StoreExtractVo>>();
			resVo.setCode(ProductResExceptionCode.STOREID_NULL.getCode());
			resVo.setMessage(ProductResExceptionCode.STOREID_NULL.getMessage());
			return resVo;
		}
		
		Map<String,Object> queryMap=new HashMap<String,Object>();
		queryMap.put("storeId", storeId);
		
		//设置返回值
		PageInfo<StoreExtractVo> storeExtractVoPage=new PageInfo<StoreExtractVo>();
		List<StoreExtractVo> listStoreExtractVo=new ArrayList<StoreExtractVo>();
				
				
		PageInfo<SystemStoreExtract> listSystemStoreExtractPage=systemStoreExtractService.getListPage(queryMap, pageIndex, pageSize);
	    //复制分页信息
		BeanUtils.copyProperties(listSystemStoreExtractPage, storeExtractVoPage);
		
		List<SystemStoreExtract> listSystemStoreExtract=listSystemStoreExtractPage.getList();
		
		if(listSystemStoreExtract!=null){
			for(SystemStoreExtract ext:listSystemStoreExtract){
				String bankName=ext.getBankName();
				String bankCode=ext.getBankCode();
				Integer status=ext.getStatus();
				Integer addTime=ext.getAddTime();
				Integer failTime=ext.getFailTime();
				
				Integer id=ext.getId();
				BigDecimal serviceCharge=ext.getServiceCharge();
				Double serviceChargeDouble=serviceCharge.doubleValue();
				
				BigDecimal extractPrice=ext.getExtractPrice();
				Double extractPriceDouble=extractPrice.doubleValue();
				
				Date passTime=ext.getPassTime();
				
				Date lastModifyDate=ext.getLastModifyDate();
				
				Date addDateTime=new Date(addTime*1000l);
				
				StoreExtractVo storeExtractVo=new StoreExtractVo();
				
				String accountWay=null;
				if(!StringUtils.isNullOrBlank(bankName)){
					accountWay=bankName+"("+bankCode.substring(bankCode.length()-4)+")";
				}else{
					accountWay="尾号"+"("+bankCode.substring(bankCode.length()-4)+")";
				}
				storeExtractVo.setAccountWay(accountWay);
				
				//-1 未通过 0 审核中 1 已提现
				if(status.equals(-1)){
					storeExtractVo.setStatus(-1);
					storeExtractVo.setStatusDesc("未通过");
				}else if(status.equals(0)){
					storeExtractVo.setStatus(0);
					storeExtractVo.setStatusDesc("审核中");
				}else if(status.equals(1)){
					storeExtractVo.setStatus(1);
					storeExtractVo.setStatusDesc("已提现");
				}
				
				if(passTime!=null){
					String passTimeStr=DateUtil.formatTime(passTime);
					storeExtractVo.setScheduleTime(passTimeStr);
				}else if(failTime!=null){
					Date failDateTime=new Date(failTime*1000l);
					String failDateTimeStr=DateUtil.formatTime(failDateTime);
					storeExtractVo.setScheduleTime(failDateTimeStr);
				}else{
					String addTimeStr=DateUtil.formatTime(addDateTime);
					storeExtractVo.setScheduleTime(addTimeStr);
				}
				storeExtractVo.setServiceCharge(String.valueOf(serviceChargeDouble));
				storeExtractVo.setAmount(String.valueOf(extractPriceDouble));
				storeExtractVo.setId(id);
				listStoreExtractVo.add(storeExtractVo);
			}
		}
		storeExtractVoPage.setList(listStoreExtractVo);
		
		ResponseVo<PageInfo<StoreExtractVo>> res = new ResponseVo<PageInfo<StoreExtractVo>>();
		res.setResult(storeExtractVoPage);
		log.info("msg1=结束提现明细清单列表,,method=queryWithdrawalApplicateByPage,,reqVo={}",queryWithdrawalApplicateByPageStr);
		return res;
	}
	
	
	@ApiOperation(value = "获取提现进度详情")
    @RequestMapping(value = "/queryWithdrawalScheduleDetail",method = {RequestMethod. POST})
    public ResponseVo<WithdrawalApplicateResultVo> queryWithdrawalScheduleDetail(@RequestParam(value = "id", required = true) Integer id){
		
		log.info("msg1=开始获取提现进度详情,,method=queryWithdrawalScheduleDetail,,id={}",id);
		if(id==null){
			ResponseVo<WithdrawalApplicateResultVo> resVo=new ResponseVo<WithdrawalApplicateResultVo>();
			resVo.setCode(ProductResExceptionCode.ID_NULL.getCode());
			resVo.setMessage(ProductResExceptionCode.ID_NULL.getMessage());
			return resVo;
		}
		
		SystemStoreExtract systemStoreExtract=systemStoreExtractService.queryByPrimaryId(id);
		
		String bankName=systemStoreExtract.getBankName();
		String bankCode=systemStoreExtract.getBankCode();
		Integer status=systemStoreExtract.getStatus();
		Integer addTime=systemStoreExtract.getAddTime();
		Integer failTime=systemStoreExtract.getFailTime();
		String failMsg=systemStoreExtract.getFailMsg();
		
		Date lastModifyDate=systemStoreExtract.getLastModifyDate();
		
		Date passTime=systemStoreExtract.getPassTime();
		
		BigDecimal serviceCharge=systemStoreExtract.getServiceCharge();
		
		Double serviceChargeDouble=serviceCharge.doubleValue();
		BigDecimal extractPrice=systemStoreExtract.getExtractPrice();
		Double extractPriceDouble=extractPrice.doubleValue();
		
		Date addDateTime=new Date(addTime*1000l);
		String addTimeStr=DateUtil.formatTime(addDateTime);
		
		
		WithdrawalApplicateResultVo withdrawalApplicateResultVo=new WithdrawalApplicateResultVo();
		List<WithdrawalApplicateScheduleVo> listSchedule=new ArrayList<WithdrawalApplicateScheduleVo>();
		
		
		String accountWay=null;
		if(!StringUtils.isNullOrBlank(bankName)){
			if(!StringUtils.isNullOrBlank(bankCode)&&bankCode.length()>4){
				accountWay=bankName+"("+bankCode.substring(bankCode.length()-4)+")";
			}else{
				accountWay=bankName+"("+bankCode+")";
			}
		}else{
			if(!StringUtils.isNullOrBlank(bankCode)&&bankCode.length()>4){
				accountWay="尾号"+"("+bankCode.substring(bankCode.length()-4)+")";
			}else{
				accountWay="尾号"+"("+bankCode+")";
			}
			
		}
		
		
		if(passTime!=null){
			String passTimeStr=DateUtil.formatTime(passTime);
			withdrawalApplicateResultVo.setScheduleTime(passTimeStr);
		}else if(failTime!=null){
			Date failDateTime=new Date(failTime*1000l);
			String failDateTimeStr=DateUtil.formatTime(failDateTime);
			withdrawalApplicateResultVo.setScheduleTime(failDateTimeStr);
		}else{
			withdrawalApplicateResultVo.setScheduleTime(addTimeStr);
		}
		
		
		//-1 未通过 0 审核中 1 已提现
		if(status.equals(-1)){
			withdrawalApplicateResultVo.setStatus(-1);
			withdrawalApplicateResultVo.setStatusDesc("未通过");
			withdrawalApplicateResultVo.setFailMsg(failMsg);
			
			
			WithdrawalApplicateScheduleVo scheduleVo1=new WithdrawalApplicateScheduleVo();
			scheduleVo1.setScheduleDate(addTimeStr);
			scheduleVo1.setWithdrawalApplicateStatus("提现申请");
			
			
			Date failDateTime=new Date(failTime*1000l);
			String failDateTimeStr=DateUtil.formatTime(failDateTime);
			
			WithdrawalApplicateScheduleVo scheduleVo2=new WithdrawalApplicateScheduleVo();
			scheduleVo2.setScheduleDate(failDateTimeStr);
			scheduleVo2.setWithdrawalApplicateStatus("审核未通过");
			
			WithdrawalApplicateScheduleVo scheduleVo3=new WithdrawalApplicateScheduleVo();
			scheduleVo3.setScheduleDate(failDateTimeStr);
			scheduleVo3.setWithdrawalApplicateStatus("提现失败");
			
			listSchedule.add(scheduleVo1);
			listSchedule.add(scheduleVo2);
			listSchedule.add(scheduleVo3);
		}else if(status.equals(0)){
			
			withdrawalApplicateResultVo.setStatus(0);
			withdrawalApplicateResultVo.setStatusDesc("审核中");
			
			WithdrawalApplicateScheduleVo scheduleVo1=new WithdrawalApplicateScheduleVo();
			scheduleVo1.setScheduleDate(addTimeStr);
			scheduleVo1.setWithdrawalApplicateStatus("提现申请");
			
			WithdrawalApplicateScheduleVo scheduleVo2=new WithdrawalApplicateScheduleVo();
			scheduleVo2.setScheduleDate(addTimeStr);
			scheduleVo2.setWithdrawalApplicateStatus("审核中");
			
			listSchedule.add(scheduleVo1);
			listSchedule.add(scheduleVo2);
			
		}else if(status.equals(1)){
			withdrawalApplicateResultVo.setStatus(1);
			withdrawalApplicateResultVo.setStatusDesc("已提现");
			
			WithdrawalApplicateScheduleVo scheduleVo1=new WithdrawalApplicateScheduleVo();
			scheduleVo1.setScheduleDate(addTimeStr);
			scheduleVo1.setWithdrawalApplicateStatus("提现申请");
			
			
			//to do获取到 真实审核通过时间  暂时用最后通过时间lastermodifydate
			
			WithdrawalApplicateScheduleVo scheduleVo2=new WithdrawalApplicateScheduleVo();
			
			String lastModifyDateStr=DateUtil.formatTime(lastModifyDate);
			
			scheduleVo2.setScheduleDate(lastModifyDateStr);
			scheduleVo2.setWithdrawalApplicateStatus("审核通过");
			
			WithdrawalApplicateScheduleVo scheduleVo3=new WithdrawalApplicateScheduleVo();
			scheduleVo3.setScheduleDate(lastModifyDateStr);
			scheduleVo3.setWithdrawalApplicateStatus("提现成功");
			
			listSchedule.add(scheduleVo1);
			listSchedule.add(scheduleVo2);
			listSchedule.add(scheduleVo3);
		}
		withdrawalApplicateResultVo.setAccountWay(accountWay);
		
		
		withdrawalApplicateResultVo.setListSchedule(listSchedule);
		withdrawalApplicateResultVo.setServiceCharge(String.valueOf(serviceChargeDouble));
		withdrawalApplicateResultVo.setAmount(String.valueOf(extractPriceDouble));
		
		ResponseVo<WithdrawalApplicateResultVo> resVo=new ResponseVo<WithdrawalApplicateResultVo>();
		resVo.setResult(withdrawalApplicateResultVo);
	    return resVo;
	}
	
	
	
	@ApiOperation(value = "计算提现手续费")
	@RequestMapping(value = "/countserviceCharge",method = {RequestMethod. POST})
	public ResponseVo<Double> countserviceCharge(
			@ApiParam(required = true, name = "countserviceChargeStr", value = "入参为countserviceChargeStr")
    		@RequestParam(value = "countserviceChargeStr", required = true) String countserviceChargeStr) throws Exception {
	
		logger.info("msg1=开始计算提现手续费,,method=countserviceCharge,,countserviceChargeStr={}",countserviceChargeStr);
		
		CountserviceChargeReqVo countserviceChargeReqVo = JSONObject.parseObject(countserviceChargeStr, CountserviceChargeReqVo.class);
		
		
		Integer storeId=countserviceChargeReqVo.getStoreId();
		//提现金额
		Double amount=countserviceChargeReqVo.getAmount();
		
		if(storeId==null){
			ResponseVo<Double> resVo=new ResponseVo<Double>();
			resVo.setCode(ProductResExceptionCode.STOREID_NULL.getCode());
			resVo.setMessage(ProductResExceptionCode.STOREID_NULL.getMessage());
			return resVo;
		}
		
		if(amount==null){
			ResponseVo<Double> resVo=new ResponseVo<Double>();
			resVo.setCode(ProductResExceptionCode.AMOUNT_NULL.getCode());
			resVo.setMessage(ProductResExceptionCode.AMOUNT_NULL.getMessage());
			return resVo;
		}
		Double serviceCharge=ServiceChargeUtil.countServiceCharge(amount);		
		
		ResponseVo<Double> res = new ResponseVo<Double>();
		res.setResult(serviceCharge);
		logger.info("msg1=结束计算提现手续费,,method=countserviceCharge,,countserviceChargeStr={}",countserviceChargeStr);
		return res;
	}
}